import { requestClient } from '#/api/request';

/**
 * 用户角色分配参数
 */
export interface UserRoleAssignParams {
  userId: number;
  roleIds: number[];
}

/**
 * 用户角色添加参数
 */
export interface UserRoleAddParams {
  userId: number;
  roleId: number;
}

/**
 * 用户角色数据
 */
export interface UserRole {
  id?: number;
  userId: number;
  roleId: number;
  createTime?: string;
}

/**
 * 用户信息（用于角色分配）
 */
export interface UserInfo {
  id: number;
  username: string;
  realName: string;
  email?: string;
  phone?: string;
  status: number;
  roles?: Array<{
    id: number;
    name: string;
    roleKey: string;
  }>;
}

/**
 * 为用户分配角色
 */
export async function assignUserRolesApi(data: UserRoleAssignParams) {
  return requestClient.post('/userRole/assign', data);
}

/**
 * 添加用户角色
 */
export async function addUserRoleApi(data: UserRoleAddParams) {
  return requestClient.post('/userRole', data);
}

/**
 * 获取用户的角色列表
 */
export async function getUserRolesApi(userId: number) {
  return requestClient.get<number[]>(`/userRole/roles/${userId}`);
}

/**
 * 删除用户角色
 */
export async function removeUserRoleApi(userId: number, roleId: number) {
  return requestClient.delete(`/userRole/${userId}/${roleId}`);
}

/**
 * 获取角色的用户ID列表
 */
export async function getRoleUsersApi(roleId: number) {
  return requestClient.get<number[]>(`/userRole/user/${roleId}`);
} 
